

#import "TablePubDictionaryItem.h"

@implementation TablePubDictionaryItem


-(NSMutableArray *) TransalteToModel:(FMResultSet*) set{
    
    NSMutableArray *array = [NSMutableArray array];
    while ([set next]) {
        Model_Pub_Dictionary_Item *model = [[Model_Pub_Dictionary_Item alloc]init];
        //DICT_ID, ITEM_ID, ITEM_CODE, ITEM_NAME, INPUT_CODE1, ORDER_NUM
        //dict_id, item_id, item_code, item_name, input_code1, order_num
        
        model.DICT_ID = [set stringForColumn:@"dict_id"];
        model.ITEM_ID = [set stringForColumn:@"item_id"];
        model.ITEM_CODE = [set stringForColumn:@"item_code"];
        model.ITEM_NAME = [set stringForColumn:@"item_name"];
        model.INPUT_CODE1 = [set stringForColumn:@"input_code1"];
        model.ORDER_NUM = [set stringForColumn:@"order_num"];
        
        if(model.INPUT_CODE1 == nil){
            model.INPUT_CODE1 = @"";
        }
        model.INPUT_CODE1 = [model.INPUT_CODE1 uppercaseString];
        
        [array addObject:model];
    }
    
    return array;
}


-(NSArray*) getListDictItemWithDictId:(NSString*)dictId{

    [DBHelper.DB open];
    
    NSString* sql = @"select * from pub_dictionary_item where dict_id = '%@'";
    sql = [NSString stringWithFormat:sql, dictId];
    
    NSString *order = @" %@ order by order_num asc";
    sql = [NSString stringWithFormat:order,sql];
    
    FMResultSet *set = [DBHelper.DB executeQuery:sql];
    NSMutableArray *array = [self TransalteToModel:set];
    
    
    [DBHelper.DB close];
    
    return array;
}
- (NSArray *)getDictItemWithItemID:(NSString *)itemID
{
    [DBHelper.DB open];
    
    NSString* sql = [NSString stringWithFormat:@"select * from pub_dictionary_item where dict_id = '019023' AND item_id = '%@'",itemID];
    FMResultSet *set = [DBHelper.DB executeQuery:sql];
    NSMutableArray *array = [self TransalteToModel:set];
    
    
    [DBHelper.DB close];
    
    return array;

}
// 夜查房查房时段
-(NSArray*) getYechafangChafangShiduan{
    return [self getListDictItemWithDictId: @"019023"];
}
@end
